package com.xmz.controller;


import cn.hutool.core.util.StrUtil;
import com.xmz.client.OrderClient;
import com.xmz.entity.User;
import com.xmz.service.IUserService;
import com.xmz.util.PageResult;
import com.xmz.util.Result;
import com.xmz.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/loadList")
    public PageResult<User> loadList( Integer pageNo,
                                      Integer pageSize,
                                     @RequestBody UserVo searchStudent){
        return  userService.loadList(pageNo,pageSize,searchStudent);
    }
    @PostMapping("/addUser")
    public Result addStudent(@Validated @RequestBody UserVo user){
        int i = userService.addUser(user);
        if(i > 0) return Result.success("添加成功！");
        return Result.error("添加失败！");
    }
    @DeleteMapping("/deleteUser")
    public Result deleteBatchStudent(@RequestBody List<Integer> id){
        int i = userService.deleteUser(id);
        if(i > 0) return Result.success("删除成功！");
        return Result.error("删除失败！");
    }
    @PutMapping("/updateUser")
    public Result updateStudent(@Validated @RequestBody User user ){
        int i = userService.updateUser(user);
        if(i > 0) return Result.success("修改成功！");
        return Result.error("修改失败！");
    }



}
